/*
 * timer.h
 *
 * The timer driver for SinhMicro's SINH51 platform.
 *
 * Copyright (C) 2024 Sinh Micro, Inc.
 * Subject to the GNU Public License, version 2.
 *
 * Author: lixiang<lixiang@sinhmicro.com>
 * 
 * Encoding format: GB2312
 * Version: v1.2.2
 * Date: 2024-11-05
 */

#ifndef __HAL_TIMER_H__
#define __HAL_TIMER_H__

#include "hal-config.h"
#include "types.h"

/*
 * timerx micros list below, and x can be 0, 1, 2, 3, 4 etc.
 * 1. TX_CNT_START
 *    timerx count start
 * 2. TX_CNT_STOP
 *    timerx count stop
 * 3. TX_CNT_VAL_GET
 *    get timerx current count value
 * 4. TX_MAX_CNT_VAL_GET
 *    get timerx max count value
 * 5. TX_IS_OF
 *    check if timerx is overflow
 * 6. TX_OF_FLAG_CLR
 *    timerx overflow flag clr
 * 7. TX_RL_VAL_TO_OF_RATIO
 *    convert timerx reload val to overflow ratio
 * 8. TX_OF_RATIO_TO_RL_VAL
 *    convert timerx overflow ratio to reload val
 */ 

#include "timer/timer-ss805x.h"		

/* 
 * timerx functions list below, and x can be 0, 1, 2, 3, 4 etc.
 *
 * 1. tx_init()
 * This function is used to init timerx.
 * @param[in] None
 * @return None  
 * 
 * 2. tx_reload_val_set(val)
 * This function is used to set the timerx reload value.
 * It can be used to modify the timerx overflow ratio, user can call 
 * TX_OF_RATIO_TO_RL_VAL() as required.
 * @param[in] val timerx reload value
 * @return None
 * Note: User should enable CONFIG_TIMERx_OF_RATIO_CHG if overflow ratio may adujuted
 * after system startup.  
 *                         
 * 3. tx_reload_val_get()
 * This function is used to get the timerx reload value.
 * @param[in] None
 * @return  timerx current reload value
 *  
 */
#if (CONFIG_USING_TIMER0 == 1)
    void t0_init(void);
    uint16_t t0_reload_val_get();
#else
    #define t0_init()
    #define t0_reload_val_get() (0)
#endif

#if (CONFIG_USING_TIMER2 == 1)
    void t2_init(void);
    void t2_reload_val_set(uint16_t val);
    uint16_t t2_reload_val_get();
#else
    #define t2_init()
    #define t2_reload_val_set(val)
    #define t2_reload_val_get() (0)
#endif

#endif
